package com.from2112.lib.net.okhttpclient;

import com.from2112.lib.net.interceptor.AddHeaderInterceptor;
import com.from2112.lib.net.interceptor.EncryptInterceptor;

import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;

/**
 * Description:
 * User: XC
 * Date: 2018-12-04
 * Time: 16:51
 */
public class CustomOkhttp {
    static OkHttpClient client;

    private static OkHttpClient getInstance() {
        if (client == null) {
            synchronized (CustomOkhttp.class) {
                if (client == null)
                    client = getClient();
            }
        }
        return client;
    }

    public static OkHttpClient getClient() {
        OkHttpClient.Builder builder = new OkHttpClient.Builder();
        builder.callTimeout(20, TimeUnit.SECONDS);   //20秒超时
        builder.addInterceptor(new AddHeaderInterceptor());
        builder.addInterceptor(new EncryptInterceptor());
        return builder.build();
    }
}
